package weixinkeji.dev.dc.base.scheme.promotions.h;

import MyUI.ligerUI.bean.LigerUIPage;
import MyUI.ligerUI.service.LigeruiService;
import weixinkeji.dev.dc.base.scheme.promotions.bean.PromotionDay;
import sys.wx.ann.hm.H;
import sys.wx.ann.hm.M;
import sys.wx.c.ATR;
import sys.wx.c.components.cv.CV;
import sys.wx.m.db.SQL.mysql.common.orderby.OrderBy;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.dao.mysql.Dao;
import sys.wx.util.datetime.date.IMYDate;
import sys.wx.util.datetime.date.MonthDay;
import weixinkeji.dev.dc.base.scheme.promotions.check.PromotionDayVOCheck;
import weixinkeji.dev.dc.base.scheme.promotions.vo.PromotionDayVO;

@H("weixinkeji/dev/dc/base/scheme/promotions/s")
public class PromotionDayHS {

    @M("/selectAll")//通过 weixinkeji/dev/dc/base/scheme/promotions/s/selectAll.imy 访问
    public static String selectAll(ATR a) {
        LigerUIPage page = LigeruiService.getPage(a.request);
        String str = null == page.sortname ? "" : OrderBy.getOrderBy(page.sortname, page.sortorder);
        String tj = getTJ_MyDate(a);

        a.printOne(LigeruiService.getGRID_1_2(
                Dao.selectVastOrderBy(PromotionDay.class, tj, page.page, page.pagesize, str), Dao.selectCount(PromotionDay.class, tj), 2)
        );
        return null;
    }

    private static String getTJ_MyDate(ATR a) {
        PromotionDayVO vo = CV.getObjectByFields(PromotionDayVO.class, a.request, new PromotionDayVOCheck().doPromotionDayVO());
        MonthDay md;
        if (null != vo) {
            if (vo.month == 0) {
                //指定年
                return Where.putThenGet(Where.TJ_IGNORE_NOTHING, null, "", "promotion_date", "LIKE",  vo.year + "%");
            }
            //指定年月
            md = IMYDate.getMyMonthStartEndDate(vo.year, vo.month);
            return Where.putBetween(null, "","", "promotion_date", md.startDate, md.endDate);

        } else {
            //默认当年当月
            md = IMYDate.getNowMonthStartEndDate(0);
            return Where.putBetween(null, "","", "promotion_date", md.startDate, md.endDate);
        }
    }
}
